package cn.getech.data.development.controller;

import cn.getech.data.development.entity.permission.InitPermission;
import cn.getech.data.development.model.dto.SysRolePermissionSaveDto;
import cn.getech.data.development.service.DataPermissionService;
import cn.getech.data.intelligence.common.utils.R;
import cn.getech.system.center.annotation.SysLog;
import cn.getech.system.center.constant.OperationModulesEnum;
import cn.getech.system.center.constant.OperationTypeEnum;
import cn.getech.system.center.constant.module.ModuleEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "权限配置")
@RestController
@RequestMapping("/bdp/role/permission")
public class SysRoleDataPermissionController {

    @Autowired
    private  DataPermissionService dataPermissionService;

    @ApiOperation(value = "保存数据源数据权限")
    @SysLog(value = "保存数据源数据权限", type = OperationTypeEnum.UPDATECODE, modulesType = OperationModulesEnum.CONFCONNECTMODELCODE,platformModuleType = ModuleEnum.AUTH_MANAGER_MODULE_CODE)
    @PostMapping("/savePermission")
    public R savePermission(@RequestBody SysRolePermissionSaveDto dto) {
        dataPermissionService.savePermission(dto.getPermissionList());
        return R.ok();
    }

    /**
     * 保存数据仓库表的权限信息
     */
    @ApiOperation("初始化权限信息")
    @PostMapping("/initPermission")
    @SysLog(value = "初始化权限信息", type = OperationTypeEnum.UPDATECODE, modulesType = OperationModulesEnum.TABLEMODELCODE,platformModuleType = ModuleEnum.AUTH_MANAGER_MODULE_CODE)
    public R initPermission( @RequestBody List<InitPermission> dataList) {
        dataPermissionService.initPermission(dataList);
        return R.ok();
    }
}


